home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WUNZ20SR.ZIP / PATTERN.C < prev    next >
C/C++ Source or Header  |  1993-04-13  |  5KB  |  143 lines

  1. #include "pattern.h"
  2. #include "wizunzip.h"
  3. #include "unzip.h"
  4. #include "helpids.h"
  5.  
  6. char __based(__segname("STRINGS_TEXT")) szNoMatch[] = 
  7.             "No entry matches the pattern!";
  8.  
  9. /****************************************************************************
  10.  
  11.     FUNCTION: PatternSelectProc(HWND, unsigned, WORD, LONG)
  12.  
  13.     PURPOSE:  Processes messages for "Select Files by Pattern" dialog box
  14.  
  15.     MESSAGES:
  16.  
  17.     WM_INITDIALOG - initialize dialog box
  18.     WM_COMMAND    - Input received
  19.  
  20. ****************************************************************************/
  21.  
  22. BOOL FAR PASCAL
  23. PatternSelectProc(HWND hwndDlg, WORD wMessage, WORD wParam, LONG lParam)
  24. {
  25. static HWND hSelect, hDeselect, hPattern;
  26. PSTR psLBEntry = NULL;  /* list box entry */
  27. PSTR psPatternBuf = NULL;    /* pattern collection    */
  28. DWORD cListItems;    /* no. items in listbox    */
  29. WORD Fname_Inx;        /* index into LB entry    */
  30. BOOL fSelect;        /* we're selecting if TRUE */
  31. int nPatternLength;    /* length of data in pattern edit window */
  32.  
  33.  
  34.     switch (wMessage) {
  35.     case WM_INITDIALOG:
  36.         hSelect = GetDlgItem(hwndDlg, IDOK);
  37.         hDeselect = GetDlgItem(hwndDlg, IDM_PATTERN_DESELECT);
  38.         hPattern = GetDlgItem(hwndDlg, IDM_PATTERN_PATTERN);
  39.         CenterDialog(GetParent(hwndDlg), hwndDlg);
  40.         return TRUE;
  41.         break;
  42.     case WM_COMMAND:
  43.         switch (wParam) {
  44.         case IDM_PATTERN_PATTERN:
  45.             if (HIWORD(lParam) == EN_CHANGE)
  46.             {
  47.             
  48.             nPatternLength = GetWindowTextLength(hPattern);
  49.             /* Enable or disable buttons depending on fullness of
  50.              * "Suffix" box.
  51.              */
  52.                 if (nPatternLength >= 0 && nPatternLength <= 1)
  53.                 {
  54.                 BOOL fButtonState = (nPatternLength > 0) ; 
  55.  
  56.                     EnableWindow(hSelect, fButtonState);
  57.                     EnableWindow(hDeselect, fButtonState);
  58.  
  59.                 }
  60.             }
  61.             break;
  62.         case IDOK: /* Select items using pattern */
  63.         case IDM_PATTERN_DESELECT:
  64.             fSelect = (BOOL)(wParam == IDOK);
  65.             /* Be sure that listbox contains at least 1 item,
  66.              * that a pattern exists (is non-null), and
  67.              * that we can buffer them.
  68.              */
  69.             if ((cListItems = SendMessage(hWndList, LB_GETCOUNT, 0, 0L)) != LB_ERR &&
  70.                  cListItems >= 1 &&
  71.                 (nPatternLength = GetWindowTextLength(hPattern)) >= 1 &&
  72.                 (psPatternBuf =    /* get a buffer    for the file name                    */
  73.               (PSTR)LocalAlloc(LMEM_FIXED, nPatternLength+1)) != NULL &&
  74.               (psLBEntry =    /* get a buffer    for the file name                    */
  75.               (PSTR)LocalAlloc(LMEM_FIXED, FILNAMSIZ+LONG_FORM_FNAME_INX)) != NULL &&
  76.                 GetWindowText(hPattern, psPatternBuf, nPatternLength+1) > 0)
  77.             {
  78.             DWORD cItemsSelected = 0; /* no. "hits" during pattern search    */
  79.             UINT uLBInx;
  80.             PSTR psPattern;    /* points to any one pattern in buffer        */
  81.             static char DELIMS[] = " \t,"; /* delimiters, mostly whitespace */
  82.  
  83.                 _strlwr(psPatternBuf);    /* convert pattern to lower case    */
  84.                  Fname_Inx = (UINT)(uf.fFormatLong ? LONG_FORM_FNAME_INX : SHORT_FORM_FNAME_INX);
  85.                 /* march through list of patterns in edit field                */
  86.                 for (psPattern = strtok(psPatternBuf, DELIMS);
  87.                      psPattern != NULL; psPattern = strtok(NULL, DELIMS))
  88.                 {
  89.                      
  90.                     /* March thru listbox matching the complete path with every entry.
  91.                      * Note: unzip's match() function probably won't work for national
  92.                      * characters above the ASCII range.
  93.                      */
  94.                     for (uLBInx = 0; uLBInx < cListItems; uLBInx++)
  95.                     {
  96.                         /* Retrieve listbox entry                                */
  97.                          if (SendMessage(hWndList, LB_GETTEXT, uLBInx, (LPARAM)((LPSTR)psLBEntry)) >
  98.                             (LRESULT)Fname_Inx)
  99.                         {
  100.                             _strlwr(&psLBEntry[Fname_Inx]); /* convert filename to lower case */
  101.                             /* Use UnZip's match() function                        */
  102.                             if (match(&psLBEntry[Fname_Inx], psPattern))
  103.                             {
  104.                                 SendMessage(hWndList, LB_SETSEL, (WPARAM)fSelect, 
  105.                                             MAKELPARAM(uLBInx,0));
  106.                                 cItemsSelected++;
  107.                             }
  108.                         }
  109.                     }
  110.                 }
  111.                 if (!cItemsSelected)    /* If no pattern match                    */
  112.                 {
  113.                     MessageBox(hwndDlg, szNoMatch, szAppName, MB_OK | MB_ICONASTERISK);
  114.                 }
  115.                 else /* one or more items were selected */
  116.                 {
  117.                     UpdateButtons(hWndMain); /* turn main push buttons on or off */
  118.                 }
  119.             }
  120.             if (psLBEntry)
  121.                 LocalFree((HLOCAL)psLBEntry);
  122.  
  123.             if (psPatternBuf)
  124.                 LocalFree((HLOCAL)psPatternBuf);
  125.             break;
  126.         case IDCANCEL:
  127.             PostMessage(hwndDlg, WM_CLOSE, 0, 0L);
  128.             break;
  129.         case IDM_PATTERN_HELP:
  130.             WinHelp(hwndDlg,szHelpFileName,HELP_CONTEXT, (DWORD)(HELPID_SELECT_BY_PATTERN));
  131.             break;
  132.         }
  133.         return TRUE;
  134.         break;
  135.     case WM_CLOSE:
  136.         DestroyWindow(hwndDlg);
  137.         hPatternSelectDlg = 0; /* flag dialog inactive    */
  138.         return TRUE;
  139.     }
  140.     return FALSE;
  141. }
  142.  
  143.